package minidb.type;

import minidb.file.FileMgr;
import minidb.buffer.BufferPool;
import minidb.record.*;
import minidb.transaction.transaction;

public class Const {
	public static final int PAGE_SIZE = 1024;
	public static final int INT_SIZE = Integer.SIZE / Byte.SIZE;
	public static final int DOUBLE_SIZE = Double.SIZE / Byte.SIZE;
	public static final int HEAD_SIZE = 4 * INT_SIZE;
	public static final int INT_NULL = Integer.MIN_VALUE;
	public static final double DOUBLE_NULL = Double.MIN_VALUE;
	public static final int CURRENT_PAGE = INT_SIZE;
	public static final int NEXT_PAGE = 0;
	public static final int PRE_PAGE = INT_SIZE*2;
	public static final int FREE = INT_SIZE * 3;
	public static final int FREEPAGE = INT_SIZE * 4;
	public static enum TYPE{ INT, STRING, CHAR, DOUBLE, DBNULL};
	public static final int leafe_length = 20*INT_SIZE;
	public static final int leafe_num = 7;
	public static FileMgr dbFile=null;
	public static BufferPool bufpool = new BufferPool(PAGE_SIZE);
	public static TablePage tablePage;
	public static java.util.HashMap<Long, transaction> TX = 
					new java.util.HashMap<Long, transaction>();
					
	public static TYPE toType(int type){
		switch(type){
			case 1:
				return TYPE.INT;
			case 2:
				return TYPE.STRING;
			case 3:
				return TYPE.CHAR;
			case 4:
				return TYPE.DOUBLE;
			default:
				return null;
		}
	}
	
	public static int toInt(TYPE type){
		if(type == TYPE.INT)
			return 1;
		else if(type == TYPE.STRING)
			return 2;
		else if(type == TYPE.CHAR)
			return 3;
		else if(type == TYPE.DOUBLE)
			return 4;
		else
			return 0;
	}
	public static void dbFile(FileMgr File){
		dbFile = File;
	}
	
	public static void tablePage(TablePage table){
		tablePage = table;
	}
}
